package com.yc.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

public class BasicServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	/**
	 * 返回数据
	 * @param resp
	 * @param result			专门用来返回1	0	2	-1这样的数据
	 */
	protected void send( HttpServletResponse resp, int result ){
		try {
			PrintWriter out = resp.getWriter();
			out.print(result);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	protected void send( HttpServletResponse resp, String result ){
		try {
			PrintWriter out = resp.getWriter();
			out.print(result);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	protected void send( HttpServletResponse resp, Object result ){
		try {
			PrintWriter out = resp.getWriter();
			Gson gson = new Gson();
			String json = gson.toJson(result);
			out.print(json);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}
